import 'package:easy_refresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:largefriends/entity/entities/lf_bool_entity.dart';
import 'package:largefriends/net/lf_dio_util.dart';
import 'package:largefriends/res/strings/lf_strings.dart';
import 'package:largefriends/utils/lf_dialog_utils.dart';

import '../../../entity/entities/lf_user_entity.dart';
import '../../../net/error_handle.dart';
import '../../../net/lf_api_url.dart';
import '../../../widgets/dialog_action_tip.dart';
import '../lf_contact_sub_logic.dart';

class LfAdmiresLogic extends LfContactSubLogic {
  @override
  Future<IndicatorResult> getCustomParamHttpRequest(
      {bool isRefresh = false}) async {
    var result = await httpRequest(httpUrl: apiLikeMe, refresh: isRefresh);
    return result;
  }

  @override
  getCustomRequestParam({bool isRefresh = false}) {}

  @override
  ContactType pageType() {
    return ContactType.likeMe;
  }

  deleteLikedMe(LfUserEntity entity) {
    showActionTips(
        tips: strRemoveUserTip.tr,
        actionButtonTip: strSure.tr,
        action: () {
          _deleteLikedRequest(entity);
        });
  }

  _deleteLikedRequest(LfUserEntity entity) {
    showLoading();
    LfDio().post<LfBoolEntity>(
        url: apiDeleteLikedMe, params: {'userId': entity.userId}).then(
      (value) {
        hideLoading();
        deleteBadgeAndEntity(entity.userId!);
        if (dataList.isEmpty) {
          getCustomRequestParam(isRefresh: true);
        } else {
          update();
        }
      },
      onError: (error) {
        hideLoading();
        if (error is NetError) {
          showSnackBar(error.msg);
        }
      },
    );
  }
}
